/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package raytracer;

/**
 *
 * @author ferco
 * Trida reprezentujici bod pruniku paprsku s objektem
 */
public class Intersection {

    // deklarace promennych
    private Vector3D point;     //bod pruniku
    private Vector3D normal;    //normala povrchu objektu
    private double distance;    //vydalenost bodu pruniku od pocatku paprsku..slouzi k urceni viditelnosti
    private Primitive primitive;    //objekt zasazeny paprskem

    /**
      *Konstruktor intersection
      *
      *@param point bod pruniku paprsku a objektu
      *@param distance vzdalenost na paprsku
      *@param primitive objekt ktery paprsek trefil
     */
    public Intersection(Vector3D point, double distance, Primitive primitive){

        this.point = point;
        this.distance = distance;
        this.primitive = primitive;
    }

    /**
      *Vrati intersection s mensi vzdalenosti od pocatku paprsku
      *
      *@param intersecB bod pruniku se kterym porovnavame vzdalenost
     */
    public Intersection closerIntersection(Intersection intersecB){

        //pokud nemame s cim porovnavat znamena to,ze toto intersection je prvni
        //takze ma nejmensi vzdalenost
        if (intersecB == null) {return this;}

        //vrati mensi z intersections
        if(this.getDistance() <= intersecB.getDistance()){
            return this;
        }
        else {
            return intersecB;
        }
    }

    public double getDistance() {
        return distance;
    }

    public Vector3D getNormal() {
        return normal;
    }

    public Vector3D getPoint() {
        return point;
    }

    public Primitive getPrimitive() {
        return primitive;
    }

    public void setNormal(Vector3D normal) {
        this.normal = normal;
    }

    public void setDistance(double distance) {
        this.distance = distance;
    }

    public void setPoint(Vector3D point) {
        this.point = point;
    }

    public void setPrimitive(Primitive primitive) {
        this.primitive = primitive;
    }



}
